package com.ebai.product.management.framework.common.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
 * 全局异常处理类
 * @author mgli
 *
 */
@ControllerAdvice
public class GlobalExceptionHandler{
	
    @ExceptionHandler(Exception.class)
    public ModelAndView handleException3(Exception ex) {
    	System.out.println("进入全局异常处理方法");
    	if(ex instanceof UnauthorizedException){
    		System.out.println("没有权限");
    		return new ModelAndView("error/unauth");
    	}
    	else if (ex instanceof NoHandlerFoundException) {
    		System.out.println("404异常");
    		return new ModelAndView("error/404");
        } 
        else {
        	System.out.println("公共错误");
        	ex.printStackTrace();
        	return new ModelAndView("error/500");
        }
    }

}
